package com.corpgovernment.common.entity;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ：xks
 * @date ：Created in 2022/5/13 14:43
 * @description：
 * @modified By：
 * @version: $
 */
public class BaseContext {
    public static final String REQUEST = "__$request__";
    public static final String RESPONSE = "__$response__";
    public static final String ACTION = "__$action__";
    private static final ThreadLocal<BaseContext> CURRENT_CONTEXT = new ThreadLocal<>();

    private final Map<String, Object> contextMap = new ConcurrentHashMap<>();

    public BaseContext() {
        set(this);
    }

    protected void initialize(BaseServiceHandler handler) {

    }
    public void put(String key, Object value) {
        contextMap.put(key, value);
    }

    public Object get(String key) {
        return contextMap.get(key);
    }

    public static void set(final BaseContext value) {
        CURRENT_CONTEXT.set(value);
    }
    public static BaseContext get() {
        return CURRENT_CONTEXT.get();
    }
    public static void remove() {
        CURRENT_CONTEXT.remove();
    }

    public Object getRequest() {
        return contextMap.get(REQUEST);
    }
}
